<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>部门账户管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#table").treegrid({
				title:"部门账户管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/finance/listFinanceDept',
				rownumbers:true,
				fitColumns:true,
				idField:'id',
				treeField: 'dept_name',
				columns:[[
				    {title:'主键',field:'id',hidden:true},
				    {title:'部门id',field:'dept_id',hidden:true},
					{title:'部门',field:'dept_name',width:200,align:'left'},
					{title:'金额',field:'money',width:100,align:'center'},
					{title:'部门统计',field:'deptDetail',fit:true,width:50,align:'center',formatter:function(value,rowDate,rowIndex){

						return "<input type='button'  style='border:0px #ff0000 solid;width:25px;height:15px;cursor:pointer'class='icon-details'  onClick=\"javascript:showDeptDetails('"+rowDate.dept_id+"','"+rowDate.dept_name+"');\"/>";
					}},
					{title:'往来明细',field:'details',fit:true,width:50,align:'center',formatter:function(value,rowDate,rowIndex){
						return "<input type='button'  style='border:0px #ff0000 solid;width:25px;height:15px;cursor:pointer'class='icon-details'  onClick='showDetails(\""+rowDate.id+"\")'/>";
					}}
				]],
				toolbar:
				[
					{
						id:'add',
						text:'新增',
						iconCls:"icon-add",
						handler:function(){
							addOrEditFinanceDept();
						}
					}
					/**,
					{
						id:'add',
						text:'重新生成所有部门账户',
						iconCls:"icon-add",
						handler:function(){
							oneKey();
						}
					}
					**/
				]
			});
		});
		
		function oneKey(){
			$.messager.prompt('确认','请输入初始值：',function(r){
				if(r != null && r !=""){
					$.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/finance/addFinanceDeptByOneKey?money='+r,
						success:function(rtJson){
							if(rtJson.rtState == "0"){
								$('#table').treegrid('reload');
							}else{
							
								$.messager.alert("提示",rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function rtCallBack(){
			$('#table').treegrid('reload');
		}
		function addOrEditFinanceDept(){
				openDialogResize("<%=contextPath %>/springViews/finance/addOrEditFinanceDept.jsp?callback=rtCallBack",1000, 800);
		}
		function showDetails(id){
			openDialogResize('<%=contextPath %>/springViews/finance/financeDeptLog.jsp?finance_dept_id='+id,1000, 800);
		}
		function showDeptDetails(dept_id,dept_name){
			openDialogResize('<%=contextPath %>/springViews/finance/financeInfo.jsp?dept_id='+dept_id+'&dept_name='+dept_name,1500, 800);
		}
	</script>
	<body >
				<div style="padding-bottom: 20px">
					<div id="table"></div>
				</div>
	</body>
</html>
